package com.gitee.wsl.doc

import java.io.BufferedReader
import java.io.FileReader
import java.io.IOException


object SampleReader {
    fun read(filename: String): String {
        val path = SampleReader::class.java.getResource(filename)?.path?:throw IllegalStateException()
        try {
            BufferedReader(FileReader(path)).use { reader ->
                var line: String? = null
                val stringBuilder = StringBuilder()
                while ((reader.readLine().also { line = it }) != null) {
                    stringBuilder.append(line)
                    stringBuilder.append(System.lineSeparator())
                }
                return stringBuilder.toString()
            }
        } catch (e: IOException) {
            throw IllegalStateException(e)
        }
    }
}